package com.lu.common.test.oss

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Button
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel

/**
 *author: luqihua
 *date:2023/11/20
 *description:
 **/
@Preview
@Composable
fun OssTestPagePrev() {
    OssTestPage()
}

@Composable
fun OssTestPage(model: OssTestModel = hiltViewModel()) {
    Column(modifier = Modifier.fillMaxSize()) {
        Button(onClick = { model.startDownload() }) {
            Text(text = "开始下载")
        }
        Button(onClick = { model.stopDownload() }) {
            Text(text = "暂停下载")
        }

        val progress by model.progressState.collectAsState()
        LinearProgressIndicator(modifier = Modifier.size(200.dp, 10.dp),
                                progress = progress,
                                color = Color.Green,
                                trackColor = Color.Red)
    }
}